<?php
require_once('include/init.php');
if($_GET['do']=='ajax')
{
    if($_GET['c']=='choseclass')
    {
        $departmentid = $_POST['departmentid'];
        $sql = "select * from nettteach_member where departmentid=".$departmentid;
        $query  = $db->query($sql);
        while($row = $db->fetch_array($query))
        {
            $classlist .= '<option value="'.$row['id'].'">'.$row['realname'].'</option>';
        }
        die($classlist);
    }
    if($_GET['c']=='chooseteacher')
    {
        $departmentid = $_POST['departmentid'];
        $sql = "select * from nettteach_member where departmentid=".$departmentid ." and type=2";
        $query  = $db->query($sql);
        while($row = $db->fetch_array($query))
        {
            $teacherlist .= '<option value="'.$row['id'].'">'.$row['realname'].'</option>';
        }
        die($teacherlist);
    }
}
include_once('main/common/header.php');
if(!($_GET['do']=='exerciseinfo'||$_GET['do']=='examinfo'||$_GET['do']=='viewcourse' || $_GET['do']=='viewvideos' ||$_GET['do'] == 'teachsource' ||$_GET['do']=='doexercise' || $_GET['do']=='message'|| $_GET['do']=='inbox'||$_GET['do']=='viewmessage'||$_GET['do']=='draft'||$_GET['do']=='editmail'||$_GET['do']=='groupmail'))
{
        
        include_once('main/common/left.php');
}
switch(fs_get_value('do'))
{
    case 'rate':
        require_once('main/teacherrate/teacherrate_index.php');
        break;
    case 'showsource':
        require_once('main/teachsource/showsource.php');
        break;
    case 'editmail':
        require_once('main/message/editmail.php');
        break;
    case 'draft':
        require_once('main/message/draft.php');
        break;
    case 'exam':
        require_once('main/exam/exam_index.php');
        break;
    case 'examlist':
        require_once('main/exam/exam_list.php');
        break;
    case 'examinfo':
        require_once('main/exam/exam_info.php');
        break;
    case 'courseware':
        require_once('main/courseware/courseware.php');
        break;
    case 'videolist':
            require_once ('main/videos/videolist.php');
            break;
    case 'leftcourseware':
        require_once('main/courseware/leftcourseware.php');
        break;
    case 'showcoursewareinfo':
        require_once('main/courseware/showcoursewareinfo.php');
        break;
    case 'coursewarelist':
            require_once ('main/courseware/coursewarelist.php');
            break;
    case 'coursewarelist_t':
        require_once('main/courseware/coursewarelist_t.php');
        break;
    case 'download_courseware':
        require_once('main/courseware/download_courseware.php');
        break;
    case 'myaccount':
        require_once('main/user/userinfo.php');
        break;
    case 'editaccount':
        require_once('main/user/editaccount.php');
        break;
    case 'video':
        require_once('main/videos/video.php');
        break;
    case 'viewvideos':
            require_once ('main/videos/viewvideos.php');
            break;
    case 'viewcourseware':
            require_once ('main/videos/viewcourseware.php');
            break;
    case 'note':
            require_once ('main/videos/note.php');
            break;
    case 'notelist':
            require_once ('main/videos/notelist.php');
            break;
    case 'search':
            require_once('main/search.php');
            break;
    case 'course':
            require_once('main/course/course.php');
            break;
    case 'viewcourse':
            require_once('main/course/viewcourse.php');
            break;
    case 'majorcourse':
            require_once('main/course/majorcourse.php');
            break;
    case 'decourse':
            require_once('main/course/decourse.php');
            break;
    case 'announce':
            require_once('main/announcement/viewannounce.php');
            break;
    case 'announcelist':
            require_once('main/announcement/announcelist.php');
            break;
    case 'exercise':
        require_once('main/exercise/exercise_index.php');
        break;
    case 'exerciselist':
        require_once('main/exercise/exercise_list.php');
        break;
    case 'exerciseinfo':
        require_once('main/exercise/exercise_info.php');
        break;
    case 'teachsource':
        require_once('main/teachsource/source_index.php');
        break;
    case 'doexercise':
        require_once('main/course/doexercise.php');
        break;
    case 'starteacherlist':
        require_once('main/star/starteacher_index.php');
        break;
    case 'starteacher':
        require_once('main/star/starteacher_info.php');
        break;
    case 'message':
        require_once('main/message/message_index.php');
        break;
    case 'inbox':
        require_once('main/message/inbox.php');
        break;
    case 'viewmessage':
         require_once('main/message/viewmessage.php');
         break;
      case 'groupmail':
         require_once('main/message/groupmail.php');
         break;
     case 'down_courseware':
         require_once('main/courseware/download_courseware.php');
         break;
    default:
        require_once('main/index.php');
      
}
//if(!($_GET['do']=='viewcourse' || $_GET['do']=='viewvideos'))
//{
//        include_once('main/common/right.php');
//        
//}
include_once('main/common/bottom.php');
if(isset($_POST['submit']))
{
    $username = $_POST['username'];
    $password = $_POST['pwd'];
    if($username!=''&&$password!='')
    {
        $query = "select * from ".DBPREFIX."member where passport='".$username."' and state='1'";
        $result = $db->query($query);
        $row = $db->fetch_array($result);
        if($row)
        {
            if($row['password']!=md5($password))
            {
                fs_showmsg('用户密码不正确');
            }
            else
            {
                //写用户登陆时间戳到cookie 用于退出的时候计算在线时间
                setcookie('teachplatform_logintime',time());
                $_SESSION['sid'] = $row['id'];
                $_SESSION['username'] = $row['passport'];//用户名
                $_SESSION['type']  =$row['type'];//会员类型
                $_SESSION['logintimes'] = $row['logintimes'];//登陆次数
                $_SESSION['realname'] = $row['realname'];//真实姓名
                $_SESSION['lastlogintime'] =$row['lastlogintime'];//上次登陆时间
                $_SESSION['photo'] =$row['photo'];//教师头像
                $update_sql  = "update ".DBPREFIX."member set lastlogintime=".time().", logintimes=logintimes+1 where id=".$_SESSION['sid'];
                $db->query($update_sql);
                fs_showmsg('登陆成功');
                
            }
        }
        else
        {
            fs_showmsg('用户名不存在');
        }
    }
}
if(fs_get_value('do')=='loginout'){
        $query = "select * from ".DBPREFIX."member where passport='".$_SESSION['username']."' and state='1'";
        $result = $db->query($query);
        $row = $db->fetch_array($result);
        //计算在线时长	以分钟为单位存入数据库
        $logintime		=	$row['lastlogintime'];
        $logouttime		=	time();
        $holdtime = $logouttime-$logintime;
        $onlinetime = gmstrftime('%H:%M:%S',$holdtime);
        /*if ( $logintime!='0' && $logouttime>$logintime )
        {
            $logintime = ($logouttime-$logintime);
            $logintime = round($logintime/60);
            $logintime = ($logintime>1200) ? 1200 : $logintime ;
            $db->query("update nettteach_member set onlinetime=onlinetime+$logintime where id= ".$_SESSION['sid']);
        }*/
//        @setcookie('7sxUserName', '', 0,'/','.7sx.org');
        //setcookie('userinfomation',null,-1);	//不用了 用上面那个
        unset($_SESSION['sid']);   
        fs_showmsg("成功退出! 您本次在线时长为[$onlinetime]",'?do=index');
//    session_unset();
//    fs_showmsg('注销成功!','?do=index');
}
?>